import 'package:flutter/material.dart';

///
/// 渐变颜色按钮
///
class CommonGradientButton extends GestureDetector {
  final String title;
  final double? fontSize;
  final Color? titleColor;
  final double? width;
  final double? height;
  final Alignment? linearStart;
  final Alignment? linearEnd;
  final double? radius;
  final List<Color>? linearColors;
  final Color? backColor;
  final FontWeight? fontWeight;
  final Function()? callBack;
  final String? iconPath;
  final double? iconSize;

  CommonGradientButton(this.radius,
      {Key? key,
      required this.title,
      this.fontSize,
      this.width,
      this.callBack,
      this.height,
      this.fontWeight,
      this.linearStart,
      this.linearEnd,
      this.linearColors,
      this.iconPath,
      this.iconSize,
      this.backColor,
      this.titleColor})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return GestureDetector(
      onTap: () {
        if (callBack != null) {
          callBack!();
        }
      },
      child: Container(
        height: height ?? 26,
        width: width ?? 315/2,
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(radius ?? 15),
            gradient: LinearGradient(
                begin: linearStart ?? Alignment.centerLeft,
                end: linearEnd ?? Alignment.centerRight,
                colors: linearColors ??
                    [const Color(0xFF5151C6), const Color(0xFF888BF4)])),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            iconPath != null
                ? Row(
                    children: [
                      Image.asset(
                        iconPath!,
                        width: iconSize ?? 25,
                        height: iconSize ?? 25,
                      )
                    ],
                  )
                : Container(),
            Text(
              title,
              style: TextStyle(
                  fontSize: fontSize ?? 16,
                  color: titleColor ?? Colors.white,
                  fontWeight: fontWeight ?? FontWeight.w600),
            )
          ],
        ),
      ),
    );
  }
}
